< previous page page_385 next page >

Page 385
    lngResult = RSInit(frmTemp)
    If lngResult = 0 Then
        lngResult = RSRead(frmTemp)
    End If
    '
    RSOpen = lngResult
    Exit Function
    '
LocalErr:
    RSOpen = Err.Number
    '
End Function
This routine accepts the user's form as a parameter, uses the property values to create a complete database and Recordset connection, and then initializes the data entry form and fills it with the first record in the dataset.
Another new twist here is that almost all the routines in this library are declared as Functions instead of Subs. These functions return an integer value that indicates whether any errors occurred during the operation. This value gives you a very easy way to check for errors from within Visual Basic code. Note that any error number returned by the Visual Basic code is sent back to the user's program for handling. This is a simple way to pass internal errors out of the class module into the caller's routine.
Tip.gif
You should comment out the On Error lines of your program while you are first entering the Visual Basic code. When the error trap is on, even simple typing errors set it off. During the construction phase, you want the Visual Basic interpreter to halt and give you a full error message. When you are sure you have eliminated all the programming bugs, you can activate the error handlers by removing the comment mark from the On Error program lines.

The RSInit Routine
The RSInit routine clears out any stray values that might exist in the form controls that you are binding to your data table. Remember that you can bind a form control to a dataset column by placing the name of the column in the Tag property of the field. This routine checks that property and, if it contains information, initializes the control to prepare it for receiving dataset values. Enter the code in Listing 10.10 as a new function.

 
< previous page page_385 next page >

If you like this book, buy it!